package com.prevpn.controller;

import com.prevpn.common.CommonResponse;
import com.prevpn.dto.GroupDeleteDTO;
import com.prevpn.dto.GroupCreatDTO;
import com.prevpn.dto.GroupUpdateDTO;
import com.prevpn.service.GroupService;
import com.prevpn.vo.GroupDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * GroupController - 对外提供组织架构接口
 */
@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    /**
     * 查询组织架构详情（基于路径）
     * 例如：
     * GET http://localhost:8080/group/queryByFullPath?directoryDomain=local&fullPath=/客服体系/专家中心/零信任专家组
     */
    //@GetMapping("/queryByFullPath")
    //public GroupDetailVO queryByFullPath(
    //        @RequestParam String directoryDomain,
    //        @RequestParam String fullPath
    //) {
    //    return groupService.queryGroupByFullPath(directoryDomain, fullPath);
    //}
    @GetMapping("/queryByFullPath")
    public CommonResponse<GroupDetailVO> queryByFullPath(
            @RequestParam String directoryDomain,
            @RequestParam String fullPath
    ) {
        return groupService.queryGroupByFullPath(directoryDomain, fullPath);
    }


    /**
     * 创建组织架构接口（别人调用我的）
     */
    @PostMapping("/create")
    public CommonResponse<Map<String, Object>> createGroup(@Validated @RequestBody GroupCreatDTO dto) {
        return groupService.createGroup(dto);
    }

    /**
     * 删除组织架构（支持批量）
     * 示例：
     * POST http://localhost:8080/group/deleteByFullPathList
     * Body:
     * {
     *     "directoryDomain": "local",
     *     "fullPathList": [
     *         "/客服体系/专家中心",
     *         "/客服体系/专家中心/零信任专家组"
     *     ]
     * }
     */
    @PostMapping("/deleteByFullPathList")
    public CommonResponse<Map<String, Object>> deleteByFullPathList(@RequestBody GroupDeleteDTO deleteDto) { // 接收一个DTO对象
        return groupService.deleteByFullPathList(deleteDto.getDirectoryDomain(), deleteDto.getFullPathList());
    }

    /**
     * 编辑组织架构
     * POST /api/group/update
     */
    @PostMapping("/update")
    public CommonResponse<Map<String, Object>> updateGroup(@RequestBody GroupUpdateDTO dto) {
        return groupService.updateGroup(dto);
    }
}
